package com.synthefact.daj.model;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.synthefact.daj.model.threaded.impl.Channel;

public class TwoMessageAssertion implements GlobalAssertionIf {

    final Logger logger = LoggerFactory.getLogger(TwoMessageAssertion.class);

    /** Expect Two messages, total */
    private static final int EXPECTED_MESSAGE_COUNT = 2;

    @Override
    public boolean test(List<ProgramIf> programs) {

	int count = 0;
	for (ProgramIf program : programs) {
	    TestProgram testProg = (TestProgram) program;
	    // count the messages in the channels
	    for (ChannelIf channel : testProg.getInChannelSet()) {
		count += ((Channel) channel).getMessages().size();
	    }

	    for (ChannelIf channel : testProg.getOutChannelSet()) {
		count += ((Channel) channel).getMessages().size();
	    }

	    // Does the current program have a message
	    if (testProg.getMsg() != null) {
		++count;
	    }
	}
	
	return count == EXPECTED_MESSAGE_COUNT;
    }

}